home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Peter Lewis / PNL Libraries / Threads.p < prev   
Encoding:
Text File  |  1994-09-28  |  5.2 KB  |  178 lines  |  [TEXT/PJMM]

  1. unit Threads;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Types,Memory;
  7.         
  8.     type
  9.         ThreadState = INTEGER;
  10.  
  11.     const
  12.         kReadyThreadState = $0;        { 0 }
  13.         kStoppedThreadState = $1;        { 1 }
  14.         kRunningThreadState = $2;        { 2 }
  15.  
  16. { Error codes have been meoved to Errors.(pah) }
  17. { Thread environment characteristics }
  18.  
  19.     type
  20.         ThreadTaskRef = Ptr;
  21.  
  22. { Thread characteristics }
  23.         ThreadStyle = LONGINT;
  24.  
  25.     const
  26.         kCooperativeThread = $1;        { 1L << 0 }
  27.         kPreemptiveThread = $2;        { 1L << 1 }
  28.  
  29. { Thread identifiers }
  30.  
  31.     type
  32.         ThreadID = LONGINT;
  33.  
  34.     const
  35.         kNoThreadID = $0;        { 0 }
  36.         kCurrentThreadID = $1;        { 1 }
  37.         kApplicationThreadID = $2;        { 2 }
  38.  
  39. { Options when creating a thread }
  40.  
  41.     type
  42.         ThreadOptions = LONGINT;
  43.  
  44.     const
  45.         kNewSuspend = $1;        { (1 << 0) }
  46.         kUsePremadeThread = $2;        { (1 << 1) }
  47.         kCreateIfNeeded = $4;        { (1 << 2) }
  48.         kFPUNotNeeded = $8;        { (1 << 3) }
  49.         kExactMatchThread = $10;        { (1 << 4) }
  50.  
  51. { Information supplied to the custom scheduler }
  52.  
  53.     type
  54.         SchedulerInfoRec = record
  55.                 InfoRecSize: LONGINT;
  56.                 CurrentThreadID: ThreadID;
  57.                 SuggestedThreadID: ThreadID;
  58.                 InterruptedCoopThreadID: ThreadID;
  59.             end;
  60.         SchedulerInfoRecPtr = ^SchedulerInfoRec;
  61.  
  62. { The following ProcPtrs cannot be interchanged with UniversalProcPtrs because of differences between 680x0}
  63. {and PowerPC runtime architectures with regard to the implementation of the Thread Manager . }
  64.  
  65. { Prototype for thread's entry (main) routine }
  66.         ThreadEntryProcPtr = ProcPtr;  { PROCEDURE (threadParam: UNIV Ptr); }
  67.  
  68. { Prototype for custom thread scheduler routine }
  69.         ThreadSchedulerProcPtr = ProcPtr;  { FUNCTION (schedulerInfo: SchedulerInfoRecPtr): ThreadID; }
  70.  
  71. { Prototype for custom thread switcher routine }
  72.         ThreadSwitchProcPtr = ProcPtr;  { PROCEDURE (threadBeingSwitched: ThreadID; switchProcParam: UNIV Ptr); }
  73.  
  74. { Prototype for thread termination notification routine }
  75.         ThreadTerminationProcPtr = ProcPtr;  { PROCEDURE (threadTerminated: ThreadID; terminationProcParam: UNIV Ptr); }
  76.  
  77. { Prototype for debugger NewThread notification }
  78.         DebuggerNewThreadProcPtr = ProcPtr;  { PROCEDURE (threadCreated: ThreadID); }
  79.  
  80. { Prototype for debugger DisposeThread notification }
  81.         DebuggerDisposeThreadProcPtr = ProcPtr;  { PROCEDURE (threadDeleted: ThreadID); }
  82.  
  83. { Prototype for debugger schedule notification }
  84.         DebuggerThreadSchedulerProcPtr = ProcPtr;  { FUNCTION (schedulerInfo: SchedulerInfoRecPtr): ThreadID; }
  85.  
  86. { Thread Manager routines }
  87.  
  88.     function CreateThreadPool (threadStyl: ThreadStyle; numToCreate: INTEGER; stackSize: Size): OSErr;
  89.     inline
  90.         $303C, $0501, $ABF2;
  91.  
  92.     function GetFreeThreadCount (threadStyl: ThreadStyle; var freeCount: INTEGER): OSErr;
  93.     inline
  94.         $303C, $0402, $ABF2;
  95.  
  96.     function GetSpecificFreeThreadCount (threadStyl: ThreadStyle; stackSize: Size; var freeCount: INTEGER): OSErr;
  97.     inline
  98.         $303C, $0615, $ABF2;
  99.  
  100.     function GetDefaultThreadStackSize (threadStyl: ThreadStyle; var stackSize: Size): OSErr;
  101.     inline
  102.         $303C, $0413, $ABF2;
  103.  
  104.     function ThreadCurrentStackSpace (thread: ThreadID; var freeStack: LONGINT): OSErr;
  105.     inline
  106.         $303C, $0414, $ABF2;
  107.  
  108.     function NewThread (threadStyl: ThreadStyle; threadEntry: ThreadEntryProcPtr; threadParam: univ Ptr; stackSize: Size; options: ThreadOptions; threadResult: univ Ptr; var threadMade: ThreadID): OSErr;
  109.     inline
  110.         $303C, $0E03, $ABF2;
  111.  
  112.     function DisposeThread (threadToDump: ThreadID; threadResult: univ Ptr; recycleThread: BOOLEAN): OSErr;
  113.     inline
  114.         $303C, $0504, $ABF2;
  115.  
  116.     function YieldToThread (suggestedThread: ThreadID): OSErr;
  117.     inline
  118.         $303C, $0205, $ABF2;
  119.  
  120.     function YieldToAnyThread: OSErr;
  121.     inline
  122.         $42A7, $303C, $0205, $ABF2;
  123.  
  124.     function GetCurrentThread (var currentThreadID: ThreadID): OSErr;
  125.     inline
  126.         $303C, $0206, $ABF2;
  127.  
  128.     function GetThreadState (threadToGet: ThreadID; var threadStat: ThreadState): OSErr;
  129.     inline
  130.         $303C, $0407, $ABF2;
  131.  
  132.     function SetThreadState (threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID): OSErr;
  133.     inline
  134.         $303C, $0508, $ABF2;
  135.  
  136.     function SetThreadStateEndCritical (threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID): OSErr;
  137.     inline
  138.         $303C, $0512, $ABF2;
  139.  
  140.     function SetThreadScheduler (threadScheduler: ThreadSchedulerProcPtr): OSErr;
  141.     inline
  142.         $303C, $0209, $ABF2;
  143.  
  144.     function SetThreadSwitcher (thread: ThreadID; threadSwitcher: ThreadSwitchProcPtr; switchProcParam: univ Ptr; inOrOut: BOOLEAN): OSErr;
  145.     inline
  146.         $303C, $070A, $ABF2;
  147.  
  148.     function SetThreadTerminator (thread: ThreadID; threadTerminator: ThreadTerminationProcPtr; terminationProcParam: univ Ptr): OSErr;
  149.     inline
  150.         $303C, $0611, $ABF2;
  151.  
  152.     function ThreadBeginCritical: OSErr;
  153.     inline
  154.         $303C, $000B, $ABF2;
  155.  
  156.     function ThreadEndCritical: OSErr;
  157.     inline
  158.         $303C, $000C, $ABF2;
  159.  
  160.     function SetDebuggerNotificationProcs (notifyNewThread: DebuggerNewThreadProcPtr; notifyDisposeThread: DebuggerDisposeThreadProcPtr; notifyThreadScheduler: DebuggerThreadSchedulerProcPtr): OSErr;
  161.     inline
  162.         $303C, $060D, $ABF2;
  163.  
  164.     function GetThreadCurrentTaskRef (var threadTRef: ThreadTaskRef): OSErr;
  165.     inline
  166.         $303C, $020E, $ABF2;
  167.  
  168.     function GetThreadStateGivenTaskRef (threadTRef: ThreadTaskRef; threadToGet: ThreadID; var threadStat: ThreadState): OSErr;
  169.     inline
  170.         $303C, $060F, $ABF2;
  171.  
  172.     function SetThreadReadyGivenTaskRef (threadTRef: ThreadTaskRef; threadToSet: ThreadID): OSErr;
  173.     inline
  174.         $303C, $0410, $ABF2;
  175.  
  176. implementation
  177.  
  178. end.